#include <QApplication>
#include <QTableView>
#include <QTextCodec>
#include <QStringList>

#include "common.h"
#include "row_text_templates.h"
#include "rows.h"
#include "columns.h"
#include "model.h"
#include "delegate.h"


using namespace BitWin;


int main(int argc, char* argv[])
{
    QApplication app(argc, argv);
    
    QTextCodec::setCodecForTr(
        QTextCodec::codecForName("UTF-8")
    );
    
    QTableView view;
    view.setWindowTitle(QObject::tr("Закройте это окно"));
    
    PRowList rows;
    rows
        << PRow(new HeaderRow("Bit No:"))
        
        << PRow(new WordRow("Word #1", 0))
        << PRow(new FieldRow("Field #1", BitRange(31, 26), 0))
        << PRow(new FieldRow("Field #2", BitRange(25, 23), 0))
        << PRow(new FieldRow("Field #3", BitRange(22, 21), 0))
        << PRow(new FieldRow("Field #4", BitRange(20, 15), 0))
        << PRow(new FieldRow("Field #5", BitRange(14, 14), 0))
        << PRow(new FieldRow("Field #6", BitRange(13, 11), 0))
        << PRow(new FieldRow("Field #7", BitRange(10, 0), 0))
        
        << PRow(new WordRow("Word #2", 1))
    ;
    
    PColumnList columns;
    columns
        << PColumn(new BitsColumn("Column #1", BitRange(31, 24)))
        << PColumn(new BitsColumn("Column #2", BitRange(23, 16)))
        << PColumn(new BitsColumn("Column #3", BitRange(15, 8)))
        << PColumn(new BitsColumn("Column #4", BitRange(7, 0)))
    ;
    
    Model* model = new Model(rows, columns);
    view.setModel(model);
    
    QAbstractItemDelegate* delegate = new Delegate();
    view.setItemDelegate(delegate);
    
    QStringList data;
    data << QString("abcd!efgh@ijkl#mnop$qrst%uvwx^yz")
         << QString("QWER+TYUI+OPAS+DFGH+JKLZ+XCVB+NM")
    ;
    model->setUp<PRowTextMaker::FromLiteral>(
        data.begin(), data.end()
    );
    
    view.show();
    
    return app.exec();
}
